package com.xmu.prcs.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.Index;
/**
 * 用户表
 * @author frequent
 *
 */
@SuppressWarnings("serial")
@Entity
@Table(name = "user", uniqueConstraints = @UniqueConstraint(columnNames = "email"))
@org.hibernate.annotations.Table(appliesTo = "user",
        indexes = {@Index(name = "idxURT", columnNames = {"registertime"})})
public class User implements Serializable {

	private Integer idUser;
	private String userName; //用户名
	private String password; //密码
	private String email; //电子邮件
	private String photo; //用户头像文件的路径
	private String address; //地址
	private Integer sex; //性别
	private Integer qqNumber; //qq号码
	private String signature; //个性签名
	private Date birthday; //生日
	private Integer zip; //邮编
	private Integer egg; //鸡蛋数
	private Integer flower;//鲜花数
	private Date registerTime;//注册时间
	private Integer status;//状态
	private Set<UserRole> userRole;//用户角色
	private Set<Favorite> favorite;//收藏的植物
	private Set<UploadPlant> uploadPlant;//上传的植物
	private Set<Topic> topic;//拥有版主权限的话题
	
	public User(){
		
	}
	
	public User(String userName, String password, String email, String photo,
			String address, Integer sex, Integer qqNumber, String signature,
			Date birthday, Integer zip, Date registerTime){
		this.userName = userName;
		this.password = password;
		this.email = email;
		this.photo = photo;
		this.address = address;
		this.sex = sex;
		this.qqNumber = qqNumber;
		this.signature = signature;
		this.birthday = birthday;
		this.zip = zip;
		this.registerTime = registerTime;
	}

	@Id
	@GeneratedValue
	@Column(name = "iduser", unique = true, nullable = true)
	public Integer getIdUser() {
		return idUser;
	}

	public void setIdUser(Integer idUser) {
		this.idUser = idUser;
	}

	@Column(name = "username", length = 20)
	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	@Column(name = "password", length = 20)
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name = "email", length = 40)
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Column(name = "photo", length = 50)
	public String getPhoto() {
		return photo;
	}

	public void setPhoto(String photo) {
		this.photo = photo;
	}

	@Column(name = "address", length = 50)
	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	@Column(name = "sex")
	public Integer getSex() {
		return sex;
	}

	public void setSex(Integer sex) {
		this.sex = sex;
	}

	@Column(name = "qqnumber")
	public Integer getQqNumber() {
		return qqNumber;
	}

	public void setQqNumber(Integer qqNumber) {
		this.qqNumber = qqNumber;
	}

	@Column(name = "signature", length = 200)
	public String getSignature() {
		return signature;
	}

	public void setSignature(String signature) {
		this.signature = signature;
	}

	@Column(name = "birthday")
	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	@Column(name = "zip")
	public Integer getZip() {
		return zip;
	}

	public void setZip(Integer zip) {
		this.zip = zip;
	}

	@Column(name = "egg")
	public Integer getEgg() {
		return egg;
	}

	public void setEgg(Integer egg) {
		this.egg = egg;
	}

	@Column(name = "flower")
	public Integer getFlower() {
		return flower;
	}

	public void setFlower(Integer flower) {
		this.flower = flower;
	}

	@Column(name = "registertime")
	public Date getRegisterTime() {
		return registerTime;
	}

	public void setRegisterTime(Date registerTime) {
		this.registerTime = registerTime;
	}

	@Column(name = "status")
	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name = "iduser")
	public Set<UserRole> getUserRole() {
		return userRole;
	}

	public void setUserRole(Set<UserRole> userRole) {
		this.userRole = userRole;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name = "iduser")
	public Set<Favorite> getFavorite() {
		return favorite;
	}

	public void setFavorite(Set<Favorite> favorite) {
		this.favorite = favorite;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name = "iduser")
	public Set<UploadPlant> getUploadPlant() {
		return uploadPlant;
	}

	public void setUploadPlant(Set<UploadPlant> uploadPlant) {
		this.uploadPlant = uploadPlant;
	}

	@ManyToMany(fetch = FetchType.LAZY, mappedBy="chargePersons")
	public Set<Topic> getTopic() {
		return topic;
	}

	public void setTopic(Set<Topic> topic) {
		this.topic = topic;
	}
	
}
